home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
mathpas.zip
/
MATH.QA
< prev
Wrap
Text File
|
1990-05-30
|
4KB
|
104 lines
TITLE: NUMERIC PROCESSING IN TURBO PASCAL
===========================================================
TP 4.0 5.0 5.5 - LARGE INTEGER TYPE SUPPORT
Q. Does Turbo Pascal 4.0+ support large integers?
A. Yes. TP 4.0+ has virtually every incarnation of 8-, 16-, and
32-bit integers: shortint, integer, longint, byte, and word.
TP 4.0 5.0 5.5 - FLOATING-POINT PARAMETERS
Q. How are floating-point numbers passed to procedures in
versions 4.0 and 5.0+?
A. In version 5.0+, the numbers are passed using the CPU stack.
However, in version 4.0, they are passed via the 80x87
coprocessor stack.
TP 4.0 5.0 5.5 - 80x87 NUMERIC COPROCESSOR
Q. How will the compiler use my 80387 coprocessor?
A. The compiler will treat it as an 8087 coprocessor and none of
it's extended capabilities will be used.
TP 4.0 5.0 5.5 - COMP TYPE USES
Q. What type is Comp? What is it useful for?
A. The Comp type is a cross between an integer and a real
type and is available when 8087 code is generated {$N+}. If no
math coprocessor is available, specify {$N+,E+} and the
emulator will support the Comp type. The compiler treats it as
a real type without an exponent. Thus Comp is useful when you
need to store extremely large numbers but don't need a decimal
point. For example, you might use variables of type Comp to
store amounts in cents and divide the value of the variable by
100 to determine what the value in dollars and cents would be.
TP 4.0 5.0 5.5 - SIGNIFICANT DIGITS OF 8087 FLOATING-POINT TYPES
Q. How many significant digits do the 8087 floating-point types
provide?
A. Type Digits of precision
-------- -------------------
single 7-8
double 15-16
extended 19-20
comp 19-20
TP 4.0 5.0 5.5 - INTERMEDIATE RESULTS OF REAL NUMBER EXPRESSIONS
Q. Are the intermediate results of real number expressions
stored in the 8087 registers?
A. Yes. In all versions, all intermediate calculations of real
number expressions are stored on the coprocessor stack.
TP 4.0 5.0 5.5 - ROUNDING WITH IEEE FLOATING-POINT
Q. How does rounding work with IEEE floating-point numbers?
A. The 8087 math coprocessor uses a different method for
rounding numbers than what you may be used to. In order to
achieve a more even distribution of values, the 8087 uses a
method sometimes called "Banker's Rounding." This method
dictates that a number will always be rounded to the nearest
EVEN number. Note that this is quite different than always
rounding UP. Here are a couple of examples:
Round(0.5) = 0
Round(1.5) = 2
TP 4.0 5.0 5.5 RANDOM RANDOMIZE - RANDOM NUMBER GENERATOR FORMULA
Q. What is the formula used by the random number generator in
Turbo Pascal?
A. The random number generator in Turbo Pascal uses 32-bit
arithmetic. It maintains a 32-bit 'seed', which is treated as
an unsigned integer. Each call to Random changes the seed by
the formula seed:=multiplier * seed + 1 mod 4294967296 Turbo
Pascal uses the multiplier, 134775813. The modulus,
4294967296, is 2 to the power 32. The multiplier was chosen
carefully for its nice randomness properties. The seed will
take on every 32-bit integer before repeating.
TP 4.0 5.0 5.5 TRUNC - CONVERTING REAL NUMBERS INTO INTEGERS
Q. How do you convert real numbers into integers?
A. Use the Round or Trunc function and assign the result to an
integer:
var i : integer;
begin
i := round(12.43); i := trunc(22.22);
end.
TP 5.0 5.5 - TAKING ADVANTAGE OF IEEE FLOATING-POINT TYPES
Q. What is the best approach to taking advantage of the new IEEE
floating-point types?
A. The new IEEE floating-point types are available when you
compile your program with {$N+} and you have a math
coprocessor; they are also available if you don't have a
coprocessor, but specify {N+,E+}. The 8087 emulator has
greater precision, but is significantly slower than the fast,
6-byte, software-only reals. When developing programs that
will be compiled and run on machines without the 8087
coprocessor, consider the tradeoffs of speed (built-in reals)
vs. precision (8087 hardware/emulation) and make the
appropriate choice.